**********************************************************************
*Patient level regs - Elevance quality 
*I. PREPARE REGRESSION FILE 
**********************************************************************
	*File options 
	if $option ==1 {
	local is is
	}
	if $option ==2 {
	local is ss
	}
	
	capture restore 
	*Assumes the construction of an episode level cardiac file, which contains 
	*readmission variables and has been merged to American Hospital Association (AHA) 
	*IDs and mergers. These processing steps are described in Appendix A1, A3. 
	use "$reg\\cardio_inp_ptnt_0_r1", clear	
	
	*CONTROL VARS AND WEIGHTS
	{
	local plan plan_prod1 plan_prod2 plan_prod3 plan_prod4 plan_rel1 plan_rel2 plan_rel3 indiv_aca indiv_offexchange_flg fullyinsured_flg 
	local pc female age elix_ inp_util_c 
	local hc2 bdtot teach mcare mcaid type_gac 	
	local area rural white college unempl poverty elderly state_exp_status 		
	local hospcontrol `hc2' `area' hhi
	local ptntcontrol `pc' `plan'
	local drg tot_drgwt
	local control never 
	local treat (incl_1`is')	
	local fe i.year i.num_prv
	local print keep(bought_1`is')
	
	*Use matching weights throughout 
	local WT "[aw=wt_cemm]"
	}
	
	*LIMIT TO TREATED, CONTROL GROUPS
	{
	foreach var in prepost* pre* post* bought* incl* never hhi hrr {
	capture drop `var'
	}
	merge m:1 num ye using "$reg\FULLsample`is'", keepusing(pre* post* bought* incl* never wt_cemm hhi hhi_hsa hrr deal_cluster within *bal_22* never_next_3yr)
	keep if _m==3 	
	drop _m
	}
	
	*ADJUST SAMPLE 
	drop if missing(tot_drgwt)
	keep if age >= 18

	*TRANSFERS
	foreach i in 30 45 60 75 90 105 {
	replace p_read`i'_inp = . if transfer==1
	}
	save "$reg\cardiosample`is'", replace